﻿#include "Vertex.h"

void FVertex::Use()
{
	glBindVertexArray(VAO);
}

void FVertexPosNormalTexcood::Init(float* VerticesArr, int32_t VerticeCount, float* IndexsArr, int32_t IndexCount)
{
	FVertex::Init(VerticesArr, VerticeCount, IndexsArr, IndexCount);

	unsigned int MyVAO;
	glGenVertexArrays(1, &MyVAO);
	glBindVertexArray(MyVAO);
	
	unsigned int VBO;
	glGenBuffers(1, &VBO);
	glBindBuffer(GL_ARRAY_BUFFER, VBO);
	glBufferData(GL_ARRAY_BUFFER, VerticeCount, VerticesArr, GL_STATIC_DRAW);

	// 位置属性
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)nullptr);
	glEnableVertexAttribArray(0);

	glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float)));
	glEnableVertexAttribArray(1);

	glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float)));
	glEnableVertexAttribArray(2);

	VAO = MyVAO;
}

void FVertexPosNormalTexcood::Destory()
{
	glDeleteVertexArrays(1, &VAO);
}

void FVertexPos::Init(float* VerticesArr, int32_t VerticeCount, float* IndexsArr, int32_t IndexCount)
{
	FVertex::Init(VerticesArr, VerticeCount, IndexsArr, IndexCount);

	uint32_t MyVAO;
	glGenVertexArrays(1, &MyVAO);
	glBindVertexArray(MyVAO);

	unsigned int VBO;
	glGenBuffers(1, &VBO);
	glBindBuffer(GL_ARRAY_BUFFER, VBO);
	glBufferData(GL_ARRAY_BUFFER, VerticeCount, VerticesArr, GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, VBO);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
	glEnableVertexAttribArray(0);

	VAO = MyVAO;
}

void FVertexPos::Destory()
{
	glDeleteVertexArrays(1, &VAO);
}
